/*
 * AutismGroupList.java
 *
 * Created on March 16, 2007, 5:35 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.asaga.tools;

import java.util.*;

/**
 * properties and methods for autism group list
 * @author jeremys
 */
public class AutismGroupList {
    
    private TreeSet groupList;
    
    /** Creates a new instance of AutismGroupList */
    public AutismGroupList() {
        this.groupList = null;
    }
    
    /**
     * constructor creates instance of object
     * @param s AutismGroupList
     */
    public AutismGroupList(TreeSet s){
        this.groupList = s;
    }
    
    /**
     * verifies if group with input group id is in group list
     * @param gid group id
     * @return something
     */
    public boolean Contains(int gid){
        if (this.groupList==null){
            return false;
        }else{
            Iterator itr = this.groupList.iterator();
            while(itr.hasNext()){
                AutismGroup ag = (AutismGroup)itr.next();
                if(ag.GetGroupId()==gid){
                    return true;
                }
            }   
        }
        return false;
    }
    
    /**
     * sets the autism group list
     * @param s autism group list
     */
    public void SetAutismGroupList(TreeSet s){
        this.groupList = s;
    }
    
    /**
     * returns the name of the group that has input group id
     * @param gid group id
     * @return group name
     */
    public String GetAutismGroupName(int gid){
        if (this.groupList==null){
            return null;
        }else{
            Iterator itr = this.groupList.iterator();
            while(itr.hasNext()){
                AutismGroup ag = (AutismGroup)itr.next();
                if(ag.GetGroupId()==gid){
                    return ag.GetGroupName();
                }
            }   
        }        
        return null;
    }
    
    /**
     * returns group id with given input group name
     * @param gname group name
     * @return group id
     */
    public int GetAutismGroupId(String gname){
        if (this.groupList==null){
            return -1;
        }else{
            Iterator itr = this.groupList.iterator();
            while(itr.hasNext()){
                AutismGroup ag = (AutismGroup)itr.next();
                if(ag.GetGroupName().equals(gname)){
                    return ag.GetGroupId();
                }
            }   
        }           
        return -1;
    }
    
    /**
     * return the stored group list
     * @return group list
     */
    public TreeSet GetAutismGroupList(){
        return this.groupList;
    }
}
